﻿<%@page import="com.rw.table.Itempicture"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="com.rw.table.Item"%>
<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  ??http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd??>

<html>
  <head>
    <base href="<%=basePath%>">
    <%@taglib prefix="s" uri="/struts-tags"%>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title>商品管理页面-B2C-racewind商城</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	
	<style  type="text/css">
			@import "./css/back/header_back.css";
			@import "./css/back/item_manage.css";
	</style>
	
	<script language="javascript" type="text/javascript" src="javascript/Admin/item_manage.js">
	</script> 
	<script language="javascript" type="text/javascript" src="javascript/commonCheck.js">
	</script> 
	

  </head>
  
  <body>
  <jsp:include flush="true" page="header_back.jsp"></jsp:include>      
     <div class="backItemFrame">		
		<div class="itemList">
			<h2><strong>商品列表</strong></h2>
	<%
    	Long indexId = (Long)request.getAttribute("indexId");
  		request.setAttribute("indexId", indexId);
    	Integer nowPage = (Integer)request.getAttribute("nowPage");
    	Integer totalPageNum = (Integer)request.getAttribute("totalPageNum");
    	DecimalFormat df = new DecimalFormat("#0.00");
    	
    	if(indexId == null || nowPage == null || totalPageNum == null){
    %>
    	<table border="0" align="center">
     		<tr>
     			<td>
     			<a>    </a> 
     			</td>
     		</tr>
     		<tr>
     			<td>
     			<a>没有可显示的数据</a> 
     			</td>
     		</tr>
     	</table>
    <%
    	}else{
    %>
			<div class="itemListTable">
			<form id="itemListShow" method="post">
				<table> 	
					<tr>
						<%
						@SuppressWarnings("unchecked")
						List<Item> itemList = (List<Item>)request.getAttribute("itemList");
						@SuppressWarnings("unchecked")
						List<Itempicture> itempictures = (List<Itempicture>)request.getAttribute("itempictures");
						if(itemList!= null && itempictures != null){
							Iterator<Item> iterator = itemList.iterator();
							Iterator<Itempicture> iterator2 = itempictures.iterator();
							while(iterator.hasNext() && iterator2.hasNext()){
								Item item = iterator.next();
								Itempicture itempicture = iterator2.next();
						%>
						<td>
						<div class="itemDetail">
							<%
								if(itempicture.getItemPicId() < 0){
							%>
							<a href=<%="displayItemInfoAction?itemId=" + item.getItemId() %>><img src="images/item/PPT.jpg"/></a>
							<%
								}else{
									String picSrc = "uploadPicture/" + itempicture.getItemPicSrc();
							%>
							<a href=<%="displayItemInfoAction?itemId=" + item.getItemId() %>><img src="<%=picSrc %>"  width="100" height="100" /></a>
							<%
								} 
							%>
							<p><%=item.getItemName() %></p>
							<p>市场价:<%=df.format(item.getItemMarketPrice()) %></p>
							<p>折扣价:<%=df.format(item.getItemMarketPrice() * item.getItemdiscount() )%></p>
							<p>
							<a href=<%="getModifyItemAction?nowPage=" + nowPage +"&itemId=" + item.getItemId()%>>修改</a>
							<%if(item.getItemDrop() == 0){ %>
							<a href=<%="changeItemStateAction?nowPage=" + nowPage +"&itemId=" + item.getItemId() + "&state=1" + "&indexId=" + indexId%>>下架</a>
							<%}else{ %>
							<a href=<%="changeItemStateAction?nowPage=" + nowPage +"&itemId=" + item.getItemId() + "&state=0" + "&indexId=" + indexId%>>上架</a>
							<%} %>
							</p>
							</div>							
						</td>
							<%} %>
						<%} %>
					</tr>					
				</table>
			</form>
			</div>
			<div class="pagechose">
				<%if(totalPageNum == 0){ %>
				<a>当前目录没有商品</a>
				<%}else{ %>
					<%if(nowPage - 1 != 0){ %>
						<a href=<%="getItemAction?nowPage=" + (nowPage - 1) +"&indexId=" + indexId%> >上一页</a> 
					<%} %>
					<%for(int i = 0; i < 4; i ++){ %>
						<%if(nowPage - 4 + i > 0){ %>
							<a href=<%="getItemAction?nowPage=" + (nowPage - 4 + i) +"&indexId=" + indexId%> ><%=(nowPage - 4 + i) %></a> 
						<%} %>
					<%} %>
					<a style="text-decoration: underline;"><%=nowPage %></a> 
					<%for(int i = 0; i < 3; i ++){ %>
						<%if(nowPage + i + 1 <= totalPageNum){ %>
							<a href=<%="getItemAction?nowPage=" + (nowPage + i + 1) +"&indexId=" + indexId%> ><%=(nowPage + i + 1) %></a> 
						<%} %>
					<%} %>
					<%if(nowPage + 1 <= totalPageNum){ %>
					<a href=<%="getItemAction?nowPage=" + (nowPage + 1) +"&indexId=" + indexId%> >下一页</a>
					<%} %>
				<%} %>
			</div>
			<hr>
		</div>
		<div class="addItem">
			<h2><strong>添加商品</strong></h2>
			<div class="addItemTable">
			<form name="addItemForm" id="addItemForm" method="post" action="addItemAction" enctype="multipart/form-data" onsubmit="return checkSingleInput()">
				<table>
					<tr>
						<td>商品名字：</td>
						<td>
							<input id="itemName" name="itemName"
							type="text" style="width:200px;height:18px" maxlength="10"/>
							</td>
						<td style="color:red">必须填写</td>					
					</tr>
					<tr>
						<td>商品描述：</td>
						<td>
							<input type="text" id="itemDescription" name="itemMsg" maxlength="100"/>
	
						</td>
						<td></td>					
					</tr>
					<tr>
						<td>商品图片：</td>
						<td>
							<s:file name="upload" label="选择文件">
							</s:file>
						</td>
						<td></td>					
					</tr>
					<tr>
						<td>市场价：</td>
						<td>
						<input type="text" name="itemMarketPrice" 
						style="width:60px;height:18px" maxlength="7"/>
						</td>
						<td style="color:red">必须填写</td>	
					</tr>
					<tr>
						<td>库存量：</td>
						<td>
						<input type="text" name="itemReserve"
						style="width:60px;height:18px" maxlength="7"/>
						</td>
						<td style="color:red">必须填写</td>	
					</tr>
					<tr>
						<td>折扣：</td>
						<td>
						<input type="text" name="itemDiscount"
						style="width:60px;height:18px"/>
						</td>
						<td style="color:red">必须填写</td>	
					</tr>
					<tr>
						<td></td>
						<td>
						<input type="submit" value="提交" onclick="return checkSingleInput()"/>
						<input type="button" value="重填" onclick="resetForm('addItemForm')"/>
					</tr>
				</table>
				<input type="hidden" name="itemParent" value=<%=indexId %> >
				<input type="hidden" name="indexId" value=<%=indexId %> >
				<input type="hidden" name="nowPage" value=<%=nowPage %> >
			</form>
			</div>
		</div>
	 </div>
     <%
    	}
     %>
     <jsp:include page="../B2C/footer.jsp" flush="true"></jsp:include>
  </body>
</html>
